using System;
using System.Collections.Generic;
using BookingSystem.Entities;
using BookingSystem.Repository;
using NHibernate.Criterion;

namespace BookingSystem.Services
{
    public class GuestService 
    {
        private readonly RepositoryBase<Guest> _repository;

        public GuestService():this(new RepositoryBase<Guest>())
        {
        }

        public GuestService(RepositoryBase<Guest> repository)
        {
            this._repository = repository;
        }

        public void Save(Guest guest)
        {
            _repository.Session.SaveOrUpdate(guest);
            _repository.Session.Flush();
        }

        public IList<Guest> GetByFirstName(string firstName)
        {
            return _repository.Session.CreateCriteria((typeof(Guest)))
               .Add(Restrictions.InsensitiveLike("FirstName", firstName ))
               .AddOrder(Order.Asc("FirstName"))
               .List<Guest>();
        }

        public IList<Guest> GetAll()
        {
            return _repository.GetAll();
        }

        public Guest Get(int id)
        {
            return _repository.GetById(id);
        }
    }
}